20-2 Ø¿Bz

§Ú­Ì¤]¥i¥H¨Ï¥Î FileSystemObject ª«¥óªº GetFolder() ¤èªk¡A§ì¥X¥Ø¿ýª«¥ó¡AµM«á¦CÁ|¦¹¥Ø¿ýª«¥óªºÄÝ©Ê¡C¨Ò¦p¡G

Example¡]fileAccess/dirProp01.asp¡^¡G

¦¹½d¨Òªº­ì©l½X¦p¤U¡G

­ì©lÀÉ¡]fileAccess/dirProp01.asp¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
<%@language=JScript%>
<% title="¦C¥X¥Ø¿ýªºÄÝ©Ê" %>
<!--#include file="../head.inc"-->
<hr>

<%
fso = Server.CreateObject("Scripting.FileSystemObject");
fileName = Request.ServerVariables("SCRIPT_NAME");
absPath = Server.MapPath(fileName);
parentDir = fso.GetParentFolderName(absPath);
dir = fso.GetFolder(parentDir);
methods = [
	"Attributes",
	"DateCreated",
	"DateLastAccessed",
	"DateLastModified",
	"Drive",
	"IsRootFolder",
	"Name",
	"ParentFolder",
	"Path",
	"ShortName",
	"ShortPath",
	"Size",
//	"SubFolders",
	"Type"];
%>
<h3 align=center>dir = <%=dir%></h3>
<table border=1 align=center>
<% for (i=0; i<methods.length; i++){
	cmd = "dir." + methods[i]; %>
	<tr><td><%=cmd%><td>&nbsp;<font color=green><%=eval(cmd)%></font>
<%}%>
</table>

<hr>
<!--#include file="../foot.inc"-->

¥t¥~¦b¬Y¨Ç±¡ªp¤U¡A§Ú­Ì§Æ±æ¯à¶}©ñ¥Ø¿ýªºÂsÄýÅv­­¡AÅý¨Ï¥ÎªÌ¬Ý¨ì¥Ø¿ýùتºÀɮצWºÙ¡A³o¤]¥i¥H¥Î ASP µ{¦¡½X¨Ó¹F¦¨¡C¨Æ¹ê¤W¡A¡u¶}©ñ¥Ø¿ýÂsÄýÅv­­¡vªº¥\¯à¥i¸g¥Ñ Web ¦øªA¾¹ªººÞ²z¨t²Î¨Ó¹F¦¨¡A¦ý¬O­n­×§ï¦¹¿ï¶µ¡A§A¥²¶·¨ã¦³ Administrator Åv­­¡C§Ú­Ìªº½d¨Ò¬Oª½±µ¨Ï¥Î ASP µ{¦¡½X¨Ó¹F¦¨¦¹¥\¯à¡A¦]¦¹¤£»Ý­n­×§ï¦øªA¾¹ªº³]©w¡C½Ð¨£¦¹½d¨Ò¡G

Example¡]fileAccess/fileList01.asp¡^¡G

¦¹½d¨Òªº­ì©l½X¦p¤U¡G

­ì©lÀÉ¡]fileAccess/fileList01.asp¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
<%@language=JScript%>
<% title="¦C¥X¥Ø¿ý¤¤ªº¤º®e" %>
<!--#include file="../head.inc"-->
<hr>

<%
fso = Server.CreateObject("Scripting.FileSystemObject");
fullPath = Server.MapPath(".");
fd = fso.GetFolder(fullPath);
%>

<h3 align=center>
Contents of <%=fullPath%>:
</h3>
<table border=1 align=center>
<tr>
<th colspan=3>File Listing</th>
<tr>
<th>File name</th><th>Size (Bytes)</th><th>Last modified</th>
<%
var fileList=new Enumerator(fd.files);
for (fileList.moveFirst(); !fileList.atEnd(); fileList.moveNext()){
	Response.Write("<tr align=center>");
	Response.Write("<td><a href=\"" + fileList.item().name + "\">" + fileList.item().name + "</a></td>");
	Response.Write("<td>" + fileList.item().size + "</td>");
	Response.Write("<td>" + fileList.item().DateLastModified + "</td>");
	Response.Write("</tr>");
}
%>
</table>
<br>
<table border=1 align=center>
<tr>
<th colspan=3>Directory Listing</th>
<tr>
<tr>
<th>Folder name</th><th>Size (Bytes)</th><th>Last modified</th>
<%
var dirList=new Enumerator(fd.SubFolders);
for (dirList.moveFirst(); !dirList.atEnd(); dirList.moveNext()){
	Response.Write("<tr align=center>");
	Response.Write("<td><a href=\"" + dirList.item().name + "\">" + dirList.item().name + "</a></td>");
	Response.Write("<td>" + dirList.item().size + "</td>");
	Response.Write("<td>" + dirList.item().DateLastModified + "</td>");
	Response.Write("</tr>");
}
%>
</table>

<hr>
<!--#include file="../foot.inc"-->

­Y¦b¦øªA¾¹¹w³]¦¹Àɮ׬°¥Ø¿ý¤¤ªº¥D¤å¥ó¡A«h·í¨Ï¥ÎªÌ³sµ²¨ì¥Ø¿ý®É¡A·|¦Û°Ê¶}±Ò¦¹ÀɮסA¨Ï¥ÎªÌ´N·|¬Ý¨ì©Ò¦³¥Ø¿ý¤º®eªº¦Cªí¡C

¦³Ãö©ó¨ä¥LÀÉ®×»P¥Ø¿ý³B²zªº¥\¯à¡A¥i±q·L³n¤½¥qªº§Þ³N¤å¥ó¬d¨ì¬ÛÃö¸ê®Æ¡C§Ú­Ì¥i¥H«Ø¥ß¤Î§R°£¥Ø¿ý¡A¥i¨£¦¹½d¨Ò¡G

Example¡]fileAccess/folderCreate01.asp¡^¡G

¦¹½d¨Òªº­ì©l½X¦p¤U¡G

­ì©lÀÉ¡]fileAccess/folderCreate01.asp¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
<%@language=JScript%>
<% title="«Ø¥ß»P§R°£¥Ø¿ý" %>
<!--#include file="../head.inc"-->
<hr>

<%
// ¨ú±oFileSystemObjectªº­ÓÅé°õ¦æ¡C
fso = new ActiveXObject("Scripting.FileSystemObject");
// ¨ú±oDrive ª«¥ó¡C
fldr = fso.GetFolder("c:");
// ¦C¦L¹w³]¸ê®Æ§¨¦WºÙ¡C
Response.Write("¹w³]¸ê®Æ§¨¦WºÙ¬O¡G" + fldr + "<br>");
// ¦C¦LºÏºÐ¦WºÙ¡C
Response.Write("ºÏºÐ¾÷¦WºÙ¡G" + fldr.Drive + "<br>");
// ¦C¦L®ÚÀɮצWºÙ¡C
if (fldr.IsRootFolder)
	Response.Write("³o¬O®Ú¥Ø¿ý¡I");
else
	Response.Write("³o¤£¬O®Ú¥Ø¿ý¡I");

Response.Write("<br><br>");
// «Ø¥ß¤@­Ó¸ê®Æ§¨ 
fso.CreateFolder ("C:\\Bogus");
Response.Write("«Ø¥ß¸ê®Æ§¨¡GC:\\Bogus" + "<br>");
// ¦C¦L¸ê®Æ§¨ªº°ò©³¦WºÙ¡C
Response.Write("Basename = " + fso.GetBaseName("c:\\bogus") + "<br>");
// §R°£¸ê®Æ§¨¡C
fso.DeleteFolder ("C:\\Bogus");
Response.Write("§R°£¸ê®Æ§¨¡GC:\\Bogus" + "<br>");
%>

<hr>
<!--#include file="../foot.inc"-->

§Ú­Ì¥i¥H¨Ï¥Î GetSpecialFolder() ¨ç¦¡¨Ó¨ú¥Î¯S®íªº¥Ø¿ý¡A¹ï©ó¤£¦Pªº¿é¤J°Ñ¼Æ¡A·|¦^¶Ç¤£¦Pªº¯S®í¥Ø¿ý¡A¦Cªí¦p¤U¡G

¿é¤J°Ñ¼Æ­È¦^¶Ç¥Ø¿ý¨å«¬­È
0Windows ¸ê®Æ§¨¡A¥]§t¥Ñ Windows §@·~¨t²Î©Ò¦w¸ËªºÀÉ®×C:\WINDOWS
1System ¸ê®Æ§¨¡A¥]§tµ{¦¡®w¡B¦r«¬©M¶gÃä³]³ÆÅX°Êµ{¦¡C:\WINDOWS\system32
2¼È¦s¸ê®Æ§¨¡A¬O¥Î¨ÓÀx¦s¼È¦sÀÉ¡C¥¦ªº¸ô®|³]¦b TMP Àô¹ÒÅܼƤ¤C:\WINDOWS\Temp

GetSpecialFolder() ªº¨Ï¥Î½d¨Ò¦p¤U¡G

Example¡]fileAccess/getSpecialFolder01.asp¡^¡G

¦¹½d¨Òªº­ì©l½X¦p¤U¡G

­ì©lÀÉ¡]fileAccess/getSpecialFolder01.asp¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
<%@language=JScript%>
<% title="¨ú±o¯S®í¥Ø¿ý" %>
<!--#include file="../head.inc"-->
<hr>

<%
fso = new ActiveXObject("Scripting.FileSystemObject");
windowsFolder = fso.GetSpecialFolder(0);	// Windows ¸ê®Æ§¨
systemFolder = fso.GetSpecialFolder(1);		// System ¸ê®Æ§¨
temporaryFolder = fso.GetSpecialFolder(2);	// ¼È¦s¸ê®Æ§¨
Response.Write("windowdsFolder = " + windowsFolder.Path + "<br>");
Response.Write("systemFolder = " + systemFolder.Path + "<br>");
Response.Write("temporaryFolder = " + temporaryFolder.Path + "<br>");
%>

<hr>
<!--#include file="../foot.inc"-->

¥Ñ®É­Ô¦bµ{¦¡³B²z¹Lµ{¤¤¡A»Ý­n¼g¤J¤@­Ó¼È¦sÀɮסA¦¹®É§Ú­Ì´N¥i¥H¨Ï¥Î GetSpecialFolder(2) ¨Ó¨ú±o¨t²Î¹w³]ªº¼È¦s¸ê®Æ§¨¡A¨Ã¥Î GetTempName() ¨Ó¨ú±o¼È¦sÀɮצWºÙ¡A¥i¨£¦¹½d¨Ò¡G

Example¡]fileAccess/getSpecialFolder02.asp¡^¡G

·í§A­«·s¸ü¤J¦¹ºô­¶®É¡A±N·|µoı¨C¦¸¼È¦sÀɮצWºÙ³£·|¤£¦P¡A¦]¦¹¤£·|»\±¼­ì¦³ªºÀɮצWºÙ¡C§A¥i¥H¨ì¦¹½d¨Òºô­¶©Ò¦L¥Xªº¼È¦sÀɮ׸ô®|¡A¬Ý¬Ý¦¹Àɮפº®e¬O§_¬°¡uHello World¡v¡C¦¹½d¨Òªº­ì©l½X¦p¤U¡G

­ì©lÀÉ¡]fileAccess/getSpecialFolder02.asp¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
<%@language=JScript%>
<% title="¼g¤J¼È¦sÀÉ®×" %>
<!--#include file="../head.inc"-->
<hr>

<%
fso = new ActiveXObject("Scripting.FileSystemObject");
tempFile = fso.GetTempName();
Response.Write("¼È¦sÀɮצWºÙ = " + tempFile + "<br>");
tempDir = fso.GetSpecialFolder(2);
Response.Write("¼È¦sÀɮ׸ô®| = " + tempDir.Path + "\\" + tempFile + "<br>");
fid = tempDir.CreateTextFile(tempFile);
fid.writeline("Hello World");
fid.close();
Response.Write("§Ú­Ì¤w¸g¦b¼È¦sÀÉ®×¼g¤J \"Hello World\"¡I<br>");
%>

<hr>
<!--#include file="../foot.inc"-->


JScript µ{¦¡³]­p»PÀ³¥Î¡G¥Î©ó¦øªA¾¹ºÝªº ASP Àô¹Ò